apiVersion: batch/v1
kind: Job
metadata:
  name: ks-devops-db-init-job
  namespace: kubesphere-devops-system
  labels:
    app: ks-devops-apiserver
    job: ks-devops-db-init
    version: latest
spec:
  backoffLimit: 6
  completions: 1
  parallelism: 1
  template:
    metadata:
      labels:
        app: ks-devops-apiserver
        job: ks-devops-db-init
        version: latest
      name: ks-devops-db-init
    spec:
      initContainers:
      - name: wait-mysql
        image: {{ busybox_repo }}:{{ busybox_tag }}
        imagePullPolicy: IfNotPresent
        command: ['sh', '-c', 'until nc -z {{ dbHost }} {{ dbPort }}; do echo "waiting for mysql"; sleep 2; done;']
      containers:
      - command: ["/flyway/sql/ddl/ddl_init.sh", "-h{{ dbHost }}", "-uroot", "--connect-timeout=5"]
        env:
        - name: PASSWORD
          value: "password"
        image: {{ ks_devops_flyway_repo }}:{{ ks_devops_flyway_tag }}
        imagePullPolicy: IfNotPresent
        name: devops-db-init
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: OnFailure
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
